<template>
	<view>
		<view class="detail-box">
			<!-- 	<view class="cu-form-group">
				<view class="title">主条码：</view>
				<input class="inpt" name="input">{{NowSelectGoods.GoodsName}}</input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">查询</button> 
			</view> -->
			<view class="cu-form-group">
				<view class="title">仓库编号：</view>
				<input class="inpt" name="input" v-model="NowSelectGoods.StoreCode"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">仓库名称：</view>
				<input class="inpt" name="input" v-model="NowSelectGoods.StoreName"></input>
				<!-- <button class="cu-btn round stop text-white">查询</button> -->
			</view>

			<view class="cu-form-group">
				<view class="title">所属机构：</view>
				<picker @change="PickerChange2" :value="index2" :range="picker2">
					<view class="picker">
						{{index2>-1?picker2[index2]:''}}
					</view>
				</picker>
			</view>
			<view class="cu-form-group">
				<view class="title">是否停用：</view>
				<switch class="section-right" :checked="treatmentStatu.checked" @change="switchChange" />

				<input class="inpt" name="input" disabled="false">{{NowSelectGoods.IsStop}}</input>
				<!-- <button class="cu-btn round stop text-white" @tap="gogoodlist">点击</button> -->
			</view>
			<!-- 	<view class="cu-form-group">
				<view class="title">批号：{{NowSelectGoods.GoodsName}}</view>
				<input class="inpt" name="input"></input> -->
			<!-- <button class="cu-btn  stop text-white" @tap="gopici">查询</button> -->
			<!-- 	</view> -->

		</view>
		<view class="cu-form-group">
			<!-- <button class="cu-btn  stop text-white" @tap="AddBillOrder">提交修改</button> -->
			<input class="inpt" name="input" disabled="true"></input>
			<button class="cu-btn  stop text-white" @tap="Add_StoreMessage">提交新增</button>
		</view>
	</view>
</template>
<script>
	import * as Api from '@/syApis/syDa/syDa.js'
	export default {
		data() {
			return {
				//选择的商品
				NowSelectGoods: {
					StoreName: "",
					StoreCode: ""
				},
				//添加的备注
				GoodsRemark: "",
				//商品库存
				GoodsStorm: 0,
				//商品税率
				Tax: 0,
				//商品
				GoodsQty: 0,
				//商品折扣
				GoodsDiscount: "",
				//机构ID
				BranchID: "",
				//当前商品在原商品数组对应的位置
				index2: 0,
				picker2: [],
				SelectStockNum: "",
				StoreList: [],
				treatmentStatu: {
					checked: false
				},
			}
		},
		created() {
			this.Get_BranchMessage();
		},
		onLoad(options) {


		},
		methods: {
			switchChange(e) {
				let value = e.target.value
				let that = this
				this.$set(this.treatmentStatu, 'checked', value) // 将点击改变的状态赋给treatmentStatu.checked
				if (value && !this.havePromise) {
					uni.showModal({
						title: '提示',
						content: '是否停用',
						success: function(res) {
							if (res.confirm) {
								that.$emit('changePage', 1)
								console.log('用户点击确定')
							} else if (res.cancel) {
								that.$set(that.treatmentStatu, 'checked', false) // 手动修改switch的状态，视图会同步更新
								console.log('用户点击取消');
							}
						}
					});
				}},
				//获取仓库
				Get_BranchMessage() {
						let data = {
							Filter: ""
						}
						this.picker2 = [];
						var that = this;
						Api.Get_BranchMessage(data, function(res) {
							if (res.state) {
								if (res.data.ErrorMsg == "获取登录信息失败") {
									Api.showTip("登录超时");
								} else if (res.data.ErrorMsg != "") {
									Api.showTip(res.data.ErrorMsg);
								} else {
									let responseData = res.data.ResultMsg;
									that.StoreList = res.data.ResultMsg;
									that.NowSelectGoods.BranchID = res.data.ResultMsg[0].BranchID;

									responseData.forEach((item, index) => {
										that.picker2.push(item.BranchName);
									});
								}
							} else {

							}
						});
					},
					PickerChange2(e) {
						console.log(e)
						this.index2 = e.detail.value;
						// this.NowSelectGoods.BranchID = this.StoreList[e.detail.value].BranchID;
					},
					//新增仓库档案
					Add_StoreMessage() {
						let CreateID = uni.getStorageSync("UserCode");
						let Save_M_Data_Json = {
							StoreCode: this.NowSelectGoods.StoreCode,
							StoreName: this.NowSelectGoods.StoreName,
							BranchID: this.StoreList[this.index2].BranchID,
							IsStop: this.treatmentStatu.checked,
							CreateID: CreateID

						};
						let data = {
							Save_M_Data_Json: JSON.stringify(Save_M_Data_Json)
						}
						var _this = this;
						Api.Add_StoreMessage(data, function(res) {
							if (res.state) {
								if (res.data.TipsMsg == 'OK') {
									Api.showTip("新增成功");

								} else if (res.data.ErrorMsg != "") {
									Api.showTip(res.data.ErrorMsg);
								} else {
									console.log(res);
								}

							} else {
								Api.showTip("服务器开小差了");
							}
						})
					},

					//折扣改变事件
					changeZk(e) {
						console.log(e);
					},

					//计算折扣后商品价格
					computPrice(item) {
						item.PFPrice = item.PFPrice * item.Qty * (item.Discount / 100) * (1 + item.Tax / 100);
						return item;
					}
			}
		}
</script>



<style lang="scss">
	@import url("./info-initialInventory.scss");
</style>
